﻿using Ext.Net;
using System;
using System.Web;

public static class BasePage
{
    private static string GetCallbackFX()
    {
        string otherFX;
        string text1 = HttpContext.Current.Request["cbFX"];
        if (text1 != null)
        {
            otherFX = text1;
        }
        else
        {
            otherFX = string.Empty;
        }
        return otherFX;
    }

    public static string GetCurrentUserName()
    {
        return (HttpContext.Current.User.Identity.IsAuthenticated ? HttpContext.Current.User.Identity.Name : string.Empty);
    }

    private static string GetOtherFX()
    {
        string otherFX;
        string text1 = HttpContext.Current.Request["oFX"];
        if (text1 != null)
        {
            otherFX = text1;
        }
        else
        {
            otherFX = string.Empty;
        }
        return otherFX;
    }

    private static string GetTabPanelID()
    {
        string otherFX;
        string text1 = HttpContext.Current.Request["tID"];
        if (text1 != null)
        {
            otherFX = text1;
        }
        else
        {
            otherFX = string.Empty;
        }
        return otherFX;
    }

    public static void RegisterCallBackFromChild(ResourceManager sm, string parameter)
    {
        string otherFunction = GetOtherFX();
        string callBack = string.Empty;
        if (string.IsNullOrEmpty(parameter))
        {
            if (!(string.IsNullOrEmpty(GetCallbackFX()) || string.IsNullOrEmpty(GetTabPanelID())))
            {
                callBack = string.Format("parent.{0}.getBody().{1}();", GetTabPanelID(), GetCallbackFX());
            }
        }
        else if (!(string.IsNullOrEmpty(GetCallbackFX()) || string.IsNullOrEmpty(GetTabPanelID())))
        {
            callBack = string.Format("parent.{0}.getBody().{1}({2});", GetTabPanelID(), GetCallbackFX(), parameter);
        }
        if (!string.IsNullOrEmpty(otherFunction) && !(string.IsNullOrEmpty(GetCallbackFX()) || string.IsNullOrEmpty(GetTabPanelID())))
        {
            callBack = callBack + string.Format("parent.{0}.getBody().{1}();", GetTabPanelID(), otherFunction);
        }
        if (!string.IsNullOrEmpty(callBack))
        {
            sm.RegisterClientScriptBlock("callBack", callBack);
        }
    }

    public static void RegisterCloseWindow(ResourceManager sm)
    {
        sm.RegisterClientScriptBlock("closeWindow", "closeWindow();");
    }
}

